<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>SDL_gfx: I:/Sources/sdlgfx/SDL_gfxBlitFunc.h Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />



</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">SDL_gfx
   &#160;<span id="projectnumber">2.0.25</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.8.0 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">I:/Sources/sdlgfx/SDL_gfxBlitFunc.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="_s_d_l__gfx_blit_func_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* </span>
<a name="l00002"></a>00002 <span class="comment"></span>
<a name="l00003"></a>00003 <span class="comment">SDL_gfxBlitFunc.h: custom blitters</span>
<a name="l00004"></a>00004 <span class="comment"></span>
<a name="l00005"></a>00005 <span class="comment">Copyright (C) 2001-2012  Andreas Schiffler</span>
<a name="l00006"></a>00006 <span class="comment"></span>
<a name="l00007"></a>00007 <span class="comment">This software is provided &#39;as-is&#39;, without any express or implied</span>
<a name="l00008"></a>00008 <span class="comment">warranty. In no event will the authors be held liable for any damages</span>
<a name="l00009"></a>00009 <span class="comment">arising from the use of this software.</span>
<a name="l00010"></a>00010 <span class="comment"></span>
<a name="l00011"></a>00011 <span class="comment">Permission is granted to anyone to use this software for any purpose,</span>
<a name="l00012"></a>00012 <span class="comment">including commercial applications, and to alter it and redistribute it</span>
<a name="l00013"></a>00013 <span class="comment">freely, subject to the following restrictions:</span>
<a name="l00014"></a>00014 <span class="comment"></span>
<a name="l00015"></a>00015 <span class="comment">1. The origin of this software must not be misrepresented; you must not</span>
<a name="l00016"></a>00016 <span class="comment">claim that you wrote the original software. If you use this software</span>
<a name="l00017"></a>00017 <span class="comment">in a product, an acknowledgment in the product documentation would be</span>
<a name="l00018"></a>00018 <span class="comment">appreciated but is not required.</span>
<a name="l00019"></a>00019 <span class="comment"></span>
<a name="l00020"></a>00020 <span class="comment">2. Altered source versions must be plainly marked as such, and must not be</span>
<a name="l00021"></a>00021 <span class="comment">misrepresented as being the original software.</span>
<a name="l00022"></a>00022 <span class="comment"></span>
<a name="l00023"></a>00023 <span class="comment">3. This notice may not be removed or altered from any source</span>
<a name="l00024"></a>00024 <span class="comment">distribution.</span>
<a name="l00025"></a>00025 <span class="comment"></span>
<a name="l00026"></a>00026 <span class="comment">Andreas Schiffler -- aschiffler at ferzkopp dot net</span>
<a name="l00027"></a>00027 <span class="comment"></span>
<a name="l00028"></a>00028 <span class="comment">*/</span>
<a name="l00029"></a>00029 
<a name="l00030"></a>00030 <span class="preprocessor">#ifndef _SDL_gfxBlitFunc_h</span>
<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="preprocessor">#define _SDL_gfxBlitFunc_h</span>
<a name="l00032"></a>00032 <span class="preprocessor"></span>
<a name="l00033"></a>00033 <span class="comment">/* Set up for C function definitions, even when using C++ */</span>
<a name="l00034"></a>00034 <span class="preprocessor">#ifdef __cplusplus</span>
<a name="l00035"></a>00035 <span class="preprocessor"></span><span class="keyword">extern</span>    <span class="stringliteral">&quot;C&quot;</span> {
<a name="l00036"></a>00036 <span class="preprocessor">#endif</span>
<a name="l00037"></a>00037 <span class="preprocessor"></span>
<a name="l00038"></a>00038 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00039"></a>00039 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00040"></a>00040 
<a name="l00041"></a>00041 <span class="preprocessor">#include &quot;SDL.h&quot;</span>
<a name="l00042"></a>00042 <span class="preprocessor">#include &quot;SDL_video.h&quot;</span>
<a name="l00043"></a>00043 
<a name="l00044"></a>00044 
<a name="l00045"></a>00045         <span class="keyword">extern</span> <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_blit_func_8c.html#a6d0c17342154e14322a281603960691a" title="Alpha adjustment table for custom blitter.">GFX_ALPHA_ADJUST_ARRAY</a>[256];
<a name="l00046"></a>00046 
<a name="l00047"></a>00047         <span class="comment">/* ---- Function Prototypes */</span>
<a name="l00048"></a>00048 
<a name="l00049"></a>00049 <span class="preprocessor">#ifdef _MSC_VER</span>
<a name="l00050"></a>00050 <span class="preprocessor"></span><span class="preprocessor">#  if defined(DLL_EXPORT) &amp;&amp; !defined(LIBSDL_GFX_DLL_IMPORT)</span>
<a name="l00051"></a>00051 <span class="preprocessor"></span><span class="preprocessor">#    define SDL_GFXBLITFUNC_SCOPE __declspec(dllexport)</span>
<a name="l00052"></a>00052 <span class="preprocessor"></span><span class="preprocessor">#  else</span>
<a name="l00053"></a>00053 <span class="preprocessor"></span><span class="preprocessor">#    ifdef LIBSDL_GFX_DLL_IMPORT</span>
<a name="l00054"></a>00054 <span class="preprocessor"></span><span class="preprocessor">#      define SDL_GFXBLITFUNC_SCOPE __declspec(dllimport)</span>
<a name="l00055"></a>00055 <span class="preprocessor"></span><span class="preprocessor">#    endif</span>
<a name="l00056"></a>00056 <span class="preprocessor"></span><span class="preprocessor">#  endif</span>
<a name="l00057"></a>00057 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00058"></a>00058 <span class="preprocessor"></span><span class="preprocessor">#ifndef SDL_GFXBLITFUNC_SCOPE</span>
<a name="l00059"></a><a class="code" href="_s_d_l__gfx_blit_func_8h.html#a8fcea397327309f4ab31a3251f15f911">00059</a> <span class="preprocessor"></span><span class="preprocessor">#  define SDL_GFXBLITFUNC_SCOPE extern</span>
<a name="l00060"></a>00060 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00061"></a>00061 <span class="preprocessor"></span>
<a name="l00062"></a>00062 
<a name="l00063"></a>00063         <a class="code" href="_s_d_l__gfx_blit_func_8h.html#a8fcea397327309f4ab31a3251f15f911">SDL_GFXBLITFUNC_SCOPE</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_blit_func_8c.html#ac51ff40d39f3dd0bd08116e8953960f8" title="Blitter for RGBA-&gt;RGBA blits with alpha adjustment.">SDL_gfxBlitRGBA</a>(SDL_Surface * src, SDL_Rect * srcrect, SDL_Surface * dst, SDL_Rect * dstrect);
<a name="l00064"></a>00064 
<a name="l00065"></a>00065         <a class="code" href="_s_d_l__gfx_blit_func_8h.html#a8fcea397327309f4ab31a3251f15f911">SDL_GFXBLITFUNC_SCOPE</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_blit_func_8c.html#a09a376775f9d8c933c7121e34fe5ecfc" title="Sets the alpha channel in a 32 bit surface.">SDL_gfxSetAlpha</a>(SDL_Surface * src, Uint8 a);
<a name="l00066"></a>00066 
<a name="l00067"></a>00067         <a class="code" href="_s_d_l__gfx_blit_func_8h.html#a8fcea397327309f4ab31a3251f15f911">SDL_GFXBLITFUNC_SCOPE</a> <span class="keywordtype">int</span> <a class="code" href="_s_d_l__gfx_blit_func_8c.html#a4ece530dca0ae46b1f5a780f85371687" title="Multiply the alpha channel in a 32bit surface.">SDL_gfxMultiplyAlpha</a>(SDL_Surface * src, Uint8 a);
<a name="l00068"></a>00068 
<a name="l00069"></a>00069         <span class="comment">/* -------- Macros */</span>
<a name="l00070"></a>00070 
<a name="l00071"></a>00071         <span class="comment">/* Define SDL macros locally as a substitute for an #include &quot;SDL_blit.h&quot;, */</span>
<a name="l00072"></a>00072         <span class="comment">/* which doesn&#39;t work since the include file doesn&#39;t get installed.       */</span>
<a name="l00073"></a>00073 
<a name="l00077"></a><a class="code" href="struct_s_d_l__gfx_blit_info.html">00077</a>         <span class="keyword">typedef</span> <span class="keyword">struct </span>{
<a name="l00078"></a><a class="code" href="struct_s_d_l__gfx_blit_info.html#a03dd1de15b100cd491eff7d823284189">00078</a>                 Uint8    *<a class="code" href="struct_s_d_l__gfx_blit_info.html#a03dd1de15b100cd491eff7d823284189">s_pixels</a>;
<a name="l00079"></a><a class="code" href="struct_s_d_l__gfx_blit_info.html#ad2f7fa9a764e75639fdb6e3b0f8a68fc">00079</a>                 <span class="keywordtype">int</span>       <a class="code" href="struct_s_d_l__gfx_blit_info.html#ad2f7fa9a764e75639fdb6e3b0f8a68fc">s_width</a>;
<a name="l00080"></a><a class="code" href="struct_s_d_l__gfx_blit_info.html#aeeec65f001e54fb93ba97cb85cb61592">00080</a>                 <span class="keywordtype">int</span>       <a class="code" href="struct_s_d_l__gfx_blit_info.html#aeeec65f001e54fb93ba97cb85cb61592">s_height</a>;
<a name="l00081"></a><a class="code" href="struct_s_d_l__gfx_blit_info.html#a25b822e4773e1db6d38aadc5c0bb126f">00081</a>                 <span class="keywordtype">int</span>       <a class="code" href="struct_s_d_l__gfx_blit_info.html#a25b822e4773e1db6d38aadc5c0bb126f">s_skip</a>;
<a name="l00082"></a><a class="code" href="struct_s_d_l__gfx_blit_info.html#ae9146d0f8b236274984127a7a1528966">00082</a>                 Uint8    *<a class="code" href="struct_s_d_l__gfx_blit_info.html#ae9146d0f8b236274984127a7a1528966">d_pixels</a>;
<a name="l00083"></a><a class="code" href="struct_s_d_l__gfx_blit_info.html#ad49412925c79a9894ea598530ea39b00">00083</a>                 <span class="keywordtype">int</span>       <a class="code" href="struct_s_d_l__gfx_blit_info.html#ad49412925c79a9894ea598530ea39b00">d_width</a>;
<a name="l00084"></a><a class="code" href="struct_s_d_l__gfx_blit_info.html#ad31494204fdd3d2cb30faba527cfb9fa">00084</a>                 <span class="keywordtype">int</span>       <a class="code" href="struct_s_d_l__gfx_blit_info.html#ad31494204fdd3d2cb30faba527cfb9fa">d_height</a>;
<a name="l00085"></a><a class="code" href="struct_s_d_l__gfx_blit_info.html#a9055858de99c49d16ef903fed31715b7">00085</a>                 <span class="keywordtype">int</span>       <a class="code" href="struct_s_d_l__gfx_blit_info.html#a9055858de99c49d16ef903fed31715b7">d_skip</a>;
<a name="l00086"></a><a class="code" href="struct_s_d_l__gfx_blit_info.html#a4b938ad61daa0a9625c6892fd46f32a2">00086</a>                 <span class="keywordtype">void</span>     *<a class="code" href="struct_s_d_l__gfx_blit_info.html#a4b938ad61daa0a9625c6892fd46f32a2">aux_data</a>;
<a name="l00087"></a><a class="code" href="struct_s_d_l__gfx_blit_info.html#a1ce90142d08a06fede5e2a13d66d17f6">00087</a>                 SDL_PixelFormat *<a class="code" href="struct_s_d_l__gfx_blit_info.html#a1ce90142d08a06fede5e2a13d66d17f6">src</a>;
<a name="l00088"></a><a class="code" href="struct_s_d_l__gfx_blit_info.html#a9596f5ea6998964e6240fae7ac17ce1e">00088</a>                 Uint8    *<a class="code" href="struct_s_d_l__gfx_blit_info.html#a9596f5ea6998964e6240fae7ac17ce1e">table</a>;
<a name="l00089"></a><a class="code" href="struct_s_d_l__gfx_blit_info.html#a177d476cb937246853b74253490436db">00089</a>                 SDL_PixelFormat *<a class="code" href="struct_s_d_l__gfx_blit_info.html#a177d476cb937246853b74253490436db">dst</a>;
<a name="l00090"></a>00090         } <a class="code" href="struct_s_d_l__gfx_blit_info.html" title="The structure passed to the low level blit functions.">SDL_gfxBlitInfo</a>;
<a name="l00091"></a>00091 
<a name="l00095"></a><a class="code" href="_s_d_l__gfx_blit_func_8h.html#ae6b2c815be86ad92310efb40d4b0b30e">00095</a> <span class="preprocessor">#define GFX_RGBA_FROM_PIXEL(pixel, fmt, r, g, b, a)                             \</span>
<a name="l00096"></a>00096 <span class="preprocessor">        {                                                                       \</span>
<a name="l00097"></a>00097 <span class="preprocessor">        r = ((pixel&amp;fmt-&gt;Rmask)&gt;&gt;fmt-&gt;Rshift)&lt;&lt;fmt-&gt;Rloss;              \</span>
<a name="l00098"></a>00098 <span class="preprocessor">        g = ((pixel&amp;fmt-&gt;Gmask)&gt;&gt;fmt-&gt;Gshift)&lt;&lt;fmt-&gt;Gloss;              \</span>
<a name="l00099"></a>00099 <span class="preprocessor">        b = ((pixel&amp;fmt-&gt;Bmask)&gt;&gt;fmt-&gt;Bshift)&lt;&lt;fmt-&gt;Bloss;              \</span>
<a name="l00100"></a>00100 <span class="preprocessor">        a = ((pixel&amp;fmt-&gt;Amask)&gt;&gt;fmt-&gt;Ashift)&lt;&lt;fmt-&gt;Aloss;              \</span>
<a name="l00101"></a>00101 <span class="preprocessor">        }</span>
<a name="l00102"></a>00102 <span class="preprocessor"></span>
<a name="l00106"></a><a class="code" href="_s_d_l__gfx_blit_func_8h.html#a7dda3984ca04929e2ea0a3679f7452a9">00106</a> <span class="preprocessor">#define GFX_DISASSEMBLE_RGBA(buf, bpp, fmt, pixel, r, g, b, a)                     \</span>
<a name="l00107"></a>00107 <span class="preprocessor">        do {                                                                       \</span>
<a name="l00108"></a>00108 <span class="preprocessor">        pixel = *((Uint32 *)(buf));                                        \</span>
<a name="l00109"></a>00109 <span class="preprocessor">        GFX_RGBA_FROM_PIXEL(pixel, fmt, r, g, b, a);                       \</span>
<a name="l00110"></a>00110 <span class="preprocessor">        pixel &amp;= ~fmt-&gt;Amask;                                              \</span>
<a name="l00111"></a>00111 <span class="preprocessor">        } while(0)</span>
<a name="l00112"></a>00112 <span class="preprocessor"></span>
<a name="l00116"></a><a class="code" href="_s_d_l__gfx_blit_func_8h.html#a64927ca5690904716f7ac93b1fcd4420">00116</a> <span class="preprocessor">#define GFX_PIXEL_FROM_RGBA(pixel, fmt, r, g, b, a)                             \</span>
<a name="l00117"></a>00117 <span class="preprocessor">        {                                                                       \</span>
<a name="l00118"></a>00118 <span class="preprocessor">        pixel = ((r&gt;&gt;fmt-&gt;Rloss)&lt;&lt;fmt-&gt;Rshift)|                         \</span>
<a name="l00119"></a>00119 <span class="preprocessor">        ((g&gt;&gt;fmt-&gt;Gloss)&lt;&lt;fmt-&gt;Gshift)|                         \</span>
<a name="l00120"></a>00120 <span class="preprocessor">        ((b&gt;&gt;fmt-&gt;Bloss)&lt;&lt;fmt-&gt;Bshift)|                         \</span>
<a name="l00121"></a>00121 <span class="preprocessor">        ((a&lt;&lt;fmt-&gt;Aloss)&lt;&lt;fmt-&gt;Ashift);                         \</span>
<a name="l00122"></a>00122 <span class="preprocessor">        }</span>
<a name="l00123"></a>00123 <span class="preprocessor"></span>
<a name="l00127"></a><a class="code" href="_s_d_l__gfx_blit_func_8h.html#a4e59f926fb98a86c01a4ffc5cc20e8d5">00127</a> <span class="preprocessor">#define GFX_ASSEMBLE_RGBA(buf, bpp, fmt, r, g, b, a)                    \</span>
<a name="l00128"></a>00128 <span class="preprocessor">        {                                                                       \</span>
<a name="l00129"></a>00129 <span class="preprocessor">        Uint32 pixel;                                   \</span>
<a name="l00130"></a>00130 <span class="preprocessor">        \</span>
<a name="l00131"></a>00131 <span class="preprocessor">        GFX_PIXEL_FROM_RGBA(pixel, fmt, r, g, b, a);    \</span>
<a name="l00132"></a>00132 <span class="preprocessor">        *((Uint32 *)(buf)) = pixel;                     \</span>
<a name="l00133"></a>00133 <span class="preprocessor">        }</span>
<a name="l00134"></a>00134 <span class="preprocessor"></span>
<a name="l00138"></a><a class="code" href="_s_d_l__gfx_blit_func_8h.html#ae3efb9e67172838c394c148a62822da6">00138</a> <span class="preprocessor">#define GFX_ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB)      \</span>
<a name="l00139"></a>00139 <span class="preprocessor">        do {                                            \</span>
<a name="l00140"></a>00140 <span class="preprocessor">        dR = (((sR-dR)*(A))/255)+dR;            \</span>
<a name="l00141"></a>00141 <span class="preprocessor">        dG = (((sG-dG)*(A))/255)+dG;            \</span>
<a name="l00142"></a>00142 <span class="preprocessor">        dB = (((sB-dB)*(A))/255)+dB;            \</span>
<a name="l00143"></a>00143 <span class="preprocessor">        } while(0)</span>
<a name="l00144"></a>00144 <span class="preprocessor"></span>
<a name="l00150"></a><a class="code" href="_s_d_l__gfx_blit_func_8h.html#a44c498dca765a515f40eecad8f19aac4">00150</a> <span class="preprocessor">#define GFX_DUFFS_LOOP4(pixel_copy_increment, width)                    \</span>
<a name="l00151"></a>00151 <span class="preprocessor">        { int n = (width+3)/4;                                                  \</span>
<a name="l00152"></a>00152 <span class="preprocessor">        switch (width &amp; 3) {                                            \</span>
<a name="l00153"></a>00153 <span class="preprocessor">        case 0: do {    pixel_copy_increment;                           \</span>
<a name="l00154"></a>00154 <span class="preprocessor">        case 3:         pixel_copy_increment;                           \</span>
<a name="l00155"></a>00155 <span class="preprocessor">        case 2:         pixel_copy_increment;                           \</span>
<a name="l00156"></a>00156 <span class="preprocessor">        case 1:         pixel_copy_increment;                           \</span>
<a name="l00157"></a>00157 <span class="preprocessor">        } while ( --n &gt; 0 );                                    \</span>
<a name="l00158"></a>00158 <span class="preprocessor">        }                                                               \</span>
<a name="l00159"></a>00159 <span class="preprocessor">        }</span>
<a name="l00160"></a>00160 <span class="preprocessor"></span>
<a name="l00161"></a>00161 
<a name="l00162"></a>00162 
<a name="l00163"></a>00163         <span class="comment">/* Ends C function definitions when using C++ */</span>
<a name="l00164"></a>00164 <span class="preprocessor">#ifdef __cplusplus</span>
<a name="l00165"></a>00165 <span class="preprocessor"></span>}
<a name="l00166"></a>00166 <span class="preprocessor">#endif</span>
<a name="l00167"></a>00167 <span class="preprocessor"></span>
<a name="l00168"></a>00168 <span class="preprocessor">#endif </span><span class="comment">/* _SDL_gfxBlitFunc_h */</span>
</pre></div></div><!-- contents -->


<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.0
</small></address>

</body>
</html>
